- import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=mm:mm-stg"

- name: make the boxe be real for real
  hosts: mm:mm-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - base
  - rkhunter
  - nagios_client
  - hosts
  - fas_client
  - sudo
  - collectd/base
  - { role: openvpn/client, when: env != "staging" and inventory_hostname.startswith('mm-frontend')  }
  - { role: nfs/client, when: inventory_hostname.startswith('mm-backend01'), mnt_dir: '/srv/pub',  nfs_src_dir: 'fedora_ftp/fedora.redhat.com/pub' }

  tasks:
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"
  - import_tasks: "{{ tasks_path }}/2fa_client.yml"
  - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: Deploy the backend
  hosts: mm-backend:mm-backend-stg
  user: root
  gather_facts: True

  vars_files:
  -  /srv/web/infra/ansible/vars/global.yml
  - "/srv/private/ansible/vars.yml"
  - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - mirrormanager/backend
  - s3-mirror
  - geoip

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: Deploy the crawler
  hosts: mm-crawler:mm-crawler-stg
  user: root
  gather_facts: True

  vars_files:
  -  /srv/web/infra/ansible/vars/global.yml
  - "/srv/private/ansible/vars.yml"
  - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - mirrormanager/crawler
  - { role: rsyncd,
      when: env != "staging" }
  - { role: openvpn/client, when: datacenter != "phx2" }

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: Deploy the frontend (web-app)
  hosts: mm-frontend:mm-frontend-stg
  user: root
  gather_facts: True

  vars_files:
  -  /srv/web/infra/ansible/vars/global.yml
  - "/srv/private/ansible/vars.yml"
  - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - mirrormanager/frontend2

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

# Do this one last, since the mirrormanager user needs to exist so that it can
# own the fedmsg certs we put in place here.
- name: Put fedmsg stuff in place
  hosts: mm:mm-stg
  user: root
  gather_facts: True

  vars_files:
  -  /srv/web/infra/ansible/vars/global.yml
  - "/srv/private/ansible/vars.yml"
  - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - fedmsg/base

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"
